﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.Common.ValueObject;

namespace ERP_RORZE_TOOL.DBAccess
{
	class RotateDAO : BaseDAO
	{
		#region Basic Method

		public static DataTable GetAll()
		{
			return ExcuteProcedure(ToolConstants.StoreProcedure.Rotate.GetAll);
		}

		public static DataTable GetOne(string rotateID)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
						CreateParameter("@RotateID", SqlDbType.NVarChar, rotateID)
                    };
				return ExcuteProcedure(ToolConstants.StoreProcedure.Rotate.GetOne, parameters);

			}
			catch(Exception e)
			{
				throw new MyException(e);
			}

		}

		public static Rotate LoadOne(string rotateID)
		{
			Rotate o = new Rotate();
			DataTable dt = GetOne(rotateID);
			if(dt.Rows.Count > 0)
			{
				o.RotateID = dt.Rows[0][ToolConstants.Entities.Rotate.FieldName.RotateID].ToString();
				o.Rotate_English = dt.Rows[0][ToolConstants.Entities.Rotate.FieldName.Rotate_English].ToString();
				o.Rotate_Japanese = dt.Rows[0][ToolConstants.Entities.Rotate.FieldName.Rotate_Japanese].ToString();

			}

			return o;
		}


		public static int Insert(Rotate o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@RotateID", SqlDbType.NVarChar, o.RotateID),
                        CreateParameter("@Rotate_English", SqlDbType.NVarChar, o.Rotate_English),
                        CreateParameter("@Rotate_Japanese", SqlDbType.NVarChar, o.Rotate_Japanese),
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.Rotate.Insert, parameters);

			}
			catch(Exception e)
			{
				throw new MyException(e);
			}

		}

		public static int Update(Rotate o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@TempID", SqlDbType.NVarChar, o.TempId),
                        CreateParameter("@RotateID", SqlDbType.NVarChar, o.RotateID),
                        CreateParameter("@Rotate_English", SqlDbType.NVarChar, o.Rotate_English),
                        CreateParameter("@Rotate_Japanese", SqlDbType.NVarChar, o.Rotate_Japanese),
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.Rotate.Update, parameters);
			}
			catch(Exception e)
			{
				throw new MyException(e);
			}
		}

		public static int Delete(Rotate o)
		{
			try
			{
				var parameters = new SqlParameter[]
                    {
                        CreateParameter("@RotateID", SqlDbType.NVarChar, o.RotateID)
                    };

				return ExecuteNonQueryProcedure(ToolConstants.StoreProcedure.Rotate.Delete, parameters);
			}
			catch(Exception e)
			{
				throw new MyException(e);
			}
		}

		public static DataTable GetTemplateTable()
		{
			DataTable table = new DataTable("333_Rotate");

			return table;
		}

		#endregion
	}
}
